﻿using AnesSystem.Models;
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnesSystem.Util
{
    public static class ZhenTongUtil
    {
        public static string ScreenFssj(this PatientLinkModel p)
        {
            try
            {
                List<string> fssjs = new List<string>();
                fssjs = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj1", "ym1", "jl1", "jytj1", "yz1", "hdz1", "zxz1" });
                DateTime fssjTime = new DateTime();
                if (fssjs.Count == 7)
                {
                    foreach (var item in fssjs)
                    {
                        DateTime curTime = TimeConvert(item);
                        if (curTime == new DateTime()) continue;
                        if (fssjTime.CompareTo(curTime) < 0)
                        {
                            fssjTime = curTime;
                        }
                    }
                }
                else
                {
                    return "";
                }
                if (fssjTime == new DateTime())
                {
                    return "";
                }
                else
                {
                    return fssjTime.ToString("yyyy-MM-dd  HH:mm");
                }
            }
            catch (Exception)
            {
                return "";
            }
        }
        public static string ScreenZtpf(this PatientLinkModel p)
        {
            try
            {
                List<string> ztpfs = new List<string>();
                ztpfs = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj3", "ym3", "jl3", "jytj3", "yz3", "hdz3", "zxz3" });
                double ztpf = 0;
                if (ztpfs.Count == 7)
                {
                    foreach (var item in ztpfs)
                    {
                        if (ztpf < item.ToDouble())
                        {
                            ztpf = item.ToDouble();
                        }
                    }
                }
                return ztpf.ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }
        public static string ScreenZjpf(this PatientLinkModel p)
        {
            try
            {
                List<string> zjpfs = new List<string>();
                zjpfs = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj4", "sj4", "jl4", "jytj4", "yz4", "hdz4", "zxz4" });
                double zjpf = 0;
                if (zjpfs.Count == 7)
                {
                    foreach (var item in zjpfs)
                    {
                        if (zjpf < item.ToDouble())
                        {
                            zjpf = item.ToDouble();
                        }
                    }
                }
                return zjpf.ToString();
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenDxyz(this PatientLinkModel p)
        {
            try
            {
                List<string> dxyzs = new List<string>();
                dxyzs = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj5", "ym5", "jl5", "jytj5", "yz5", "hdz5", "zxz5" });
                string dxyz = "无";
                if (dxyzs.Count == 7)
                {
                    foreach (var item in dxyzs)
                    {
                        if (item.Equals("有"))
                        {
                            dxyz = item;
                            break;
                        }
                    }
                }
                return dxyz;
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenEx(this PatientLinkModel p)
        {
            try
            {
                List<string> exs = new List<string>();
                exs = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj6", "ym3", "jl3", "jytj3", "yz3", "hdz3", "zxz3" });
                string ex = "无";
                if (exs.Count == 7)
                {
                    foreach (var item in exs)
                    {
                        if (item.Equals("有"))
                        {
                            ex = item;
                            break;
                        }
                    }
                }
                return ex;
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenOt(this PatientLinkModel p)
        {
            try
            {
                List<string> ots = new List<string>();
                ots = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj7", "ym7", "jl7", "jytj7", "yz7", "hdz7", "zxz7" });
                string ot = "无";
                if (ots.Count == 7)
                {
                    foreach (var item in ots)
                    {
                        if (item.Equals("有"))
                        {
                            ot = item;
                            break;
                        }
                    }
                }
                return ot;
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenSy(this PatientLinkModel p)
        {
            try
            {
                List<string> sys = new List<string>();
                sys = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj8", "ym8", "jl8", "jytj8", "yz8", "hdz8", "zxz8" });
                string sy = "无";
                if (sys.Count == 7)
                {
                    foreach (var item in sys)
                    {
                        if (item.Equals("有"))
                        {
                            sy = item;
                            break;
                        }
                    }
                }
                return sy;
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenNzl(this PatientLinkModel p)
        {
            try
            {
                List<string> nzls = new List<string>();
                nzls = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj9", "ym9", "jl9", "jytj9", "yz9", "hdz9", "zxz9" });
                string nzl = "无";
                if (nzls.Count == 7)
                {
                    foreach (var item in nzls)
                    {
                        if (item.Equals("有"))
                        {
                            nzl = item;
                            break;
                        }
                    }
                }
                return nzl;
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenYdza(this PatientLinkModel p)
        {
            try
            {
                List<string> ydzas = new List<string>();
                ydzas = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj10", "ym10", "jl10", "jytj10", "yz10", "hdz10", "zxz10" });
                string ydza = "无";
                if (ydzas.Count == 7)
                {
                    foreach (var item in ydzas)
                    {
                        if (item.Equals("有"))
                        {
                            ydza = item;
                            break;
                        }
                    }
                }
                return ydza;
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenGjza(this PatientLinkModel p)
        {
            try
            {
                List<string> gjzas = new List<string>();
                gjzas = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj11", "ym3", "jl11", "jytj11", "yz11", "hdz11", "zxz11" });
                string gjza = "无";
                if (gjzas.Count == 7)
                {
                    foreach (var item in gjzas)
                    {
                        if (item.Equals("有"))
                        {
                            gjza = item;
                            break;
                        }
                    }
                }
                return gjza;
            }
            catch (Exception)
            {

                return "";
            }
        }
        public static string ScreenPCA(this PatientLinkModel p)
        {
            try
            {
                List<string> pcas = new List<string>();
                pcas = DataManager.Instance.GetXMLTableValue(p, "ShuHouZhenTong", new string[] { "sj12", "ym12", "jl12", "jytj12", "yz12", "hdz12", "zxz12" });
                double pca = 0;
                if (pcas.Count == 7)
                {
                    foreach (var item in pcas)
                    {
                        if (pca < item.ToDouble())
                        {
                            pca = item.ToDouble();
                        }
                    }
                }
                return pca.ToString();
            }
            catch (Exception)
            {

                return "";
            }
        }

        public static DateTime TimeConvert(string value)
        {
            if (string.IsNullOrEmpty(value))
                return new DateTime();
            try
            {
                return Convert.ToDateTime(value + ":00");
            }
            catch (Exception)
            {
                return new DateTime();
            }
        }
    }
}
